package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.MessageManager;
import com.itheima.domain.db.User;
import com.itheima.vo.HuanXinVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class MessageController {

    @Autowired
    private MessageManager messageManager;

    // 手机端认证信息
    @GetMapping("/huanxin/user")
    public ResponseEntity huanxinAuthc() {
        // 解析token
        User user = UserHolder.get();

        // 返回
        HuanXinVo huanXinVo = new HuanXinVo();
        huanXinVo.setUsername(user.getId().toString()); // 用户id
        huanXinVo.setPassword("123456");// 用户密码
        return ResponseEntity.ok(huanXinVo);
    }

    // 打招呼（聊一下）
    @PostMapping("/tanhua/strangerQuestions")
    public void liaoYiXia(@RequestBody Map<String, String> map) {
        // 1.接收参数
        Long jiaRenId = Long.parseLong(map.get("userId"));
        String reply = map.get("reply");

        // 2.调用manager
        messageManager.liaoYiXia(jiaRenId, reply);
    }

    // 添加好友
    @PostMapping("/messages/contacts")
    public void addFriend(@RequestBody Map<String, Long> map) {
        // 1. 接收请求参数
        Long friendId = map.get("userId");
        // 2.调用manager
        messageManager.addFriend(friendId);
    }

    // 查看好友列表
    @GetMapping("/messages/contacts")
    public ResponseEntity findContactVoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ) {
        // 调用manager
        return messageManager.findContactVoByPage(pageNum, pageSize);
    }


    // 查看对你点赞人
    @GetMapping("/messages/likes")
    public ResponseEntity findLikes(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        // 确定类型
        Integer commentType = 1;
        // 调用manager
        return messageManager.findByCommentType(pageNum,pageSize,commentType);
    }

    // 查看对你评论人
    @GetMapping("/messages/comments")
    public ResponseEntity findComments(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        // 确定类型
        Integer commentType = 2;
        // 调用manager
        return messageManager.findByCommentType(pageNum,pageSize,commentType);
    }
    // 查看对你喜欢人
    @GetMapping("/messages/loves")
    public ResponseEntity findLoves(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        // 确定类型
        Integer commentType = 3;
        // 调用manager
        return messageManager.findByCommentType(pageNum,pageSize,commentType);
    }
}
